package com.googlecode.compliancechecker;

import java.io.IOException;
import java.io.InputStream;

/**
 * Utility class to verify that a {@link AndroidJar} satifies a given reference.
 * 
 * @author Marc-Christian Schulze
 * 
 */
public class ReferenceVerifier {

	private AndroidJar	jar;

	public ReferenceVerifier(AndroidJar jar) throws IOException {
		this.jar = jar;
	}

	public boolean verify(TypeReference ref) throws IOException {
		InputStream stream = jar.openClass(ref.getTypeName());
		if (stream == null) {
			return false;
		}
		try {
			if (ref instanceof MethodReference) {
				MethodReferenceVerifier verifier;
				verifier = new MethodReferenceVerifier(stream);
				return verifier.verify((MethodReference) ref);
			}
		} finally {
			if (stream != null) {
				stream.close();
			}
		}
		return true;
	}
}
